package com.definity.toolkit.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.definity.toolkit.message.Message;

public class ErrorMessageServlet extends HttpServlet {

	private static final long serialVersionUID = -6064978547190292552L;

	public ErrorMessageServlet() {

	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		execute(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		execute(req, resp);
	}

	@SuppressWarnings("unchecked")
	private void execute(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		PrintWriter out = resp.getWriter();
		
		List<Message> messages = (List<Message>) req.getAttribute("messages");
		for (Message message : messages) {
			out.append("<li>");
			out.append(message.getMessage());
			out.append("</li>");
		}
	}
	
}
